package ink.lovejinhu.leetcode;

import java.util.HashMap;
import java.util.Set;

/**
 * @author jinhu
 * created 2021-07-15 9:22
 */
public class Solution_0409 {
    /**
     * 最长回文子串
     *
     * @param s
     * @return
     */
    public int longestPalindrome(String s) {
        char[] chars = s.toCharArray();
        HashMap<Character, Integer> map = new HashMap<>();
        for (int i = 0; i < chars.length; i++) {
            if (map.containsKey(chars[i])) {
                Integer integer = map.get(chars[i]);
                map.put(chars[i], integer + 1);
            } else {
                map.put(chars[i], 1);
            }
        }
        Set<Character> keySet = map.keySet();
        boolean flag = false;  //是否有单个的
        int res = 0;
        for (char temp : keySet
        ) {
            Integer integer = map.get(temp);
            res = res + (integer / 2) * 2;
            if (integer % 2 == 1) {
                flag = true;
            }

        }

        return flag ? res + 1 : res;
    }


}
